package com.cjw.controller.soulRead;

import com.cjw.config.annotation.OperationLogAnnotation;
import com.cjw.enums.share.SharingType;
import com.cjw.pojo.dto.database.PageDTO;
import com.cjw.pojo.dto.soulread.DetailReadDTO;
import com.cjw.pojo.dto.soulread.ReadDTO;
import com.cjw.service.soulread.ReadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @create_time: 2021.1.31
 * @author : cjw
 */
@RestController
@RequestMapping("/user/read")
@Api("朗读资源")
public class ReadController {
    @Autowired
    private ReadService readService;

    @PostMapping("/findAllRead")
    @ApiOperation("查看全部朗读")
    @OperationLogAnnotation(operModul = "心灵倾听-心灵分享",operType = "查看全部朗读",operDesc = "查询")
    public PageDTO<List<ReadDTO>> findAllRead(Integer page, Integer size, String find, Long tagId) {
        if (page == null || page < 0 || size==null || size <= 0) {
            return null;
        }
        return readService.findAllRead(page, size, find, tagId);
    }

    @PostMapping("/findDetailRead")
    @ApiOperation("查询朗读详情")
    @OperationLogAnnotation(operModul = "心灵倾听-心灵分享",operType = "查看朗读详情",operDesc = "查询")
    public DetailReadDTO findDetailRead(Long readId) {
        return readService.findDetailRead(readId);
    }

    @PostMapping("/love")
    @ApiOperation("点赞")
    @OperationLogAnnotation(operModul = "心灵倾听-心灵分享",operType = "点赞朗读",operDesc = "添加")
    public Boolean love(Long readId) {
        return readService.loveCollection(readId, SharingType.LOVE.getCode());
    }

    @PostMapping("/collection")
    @ApiOperation("收藏")
    @OperationLogAnnotation(operModul = "心灵倾听-心灵分享",operType = "收藏朗读",operDesc = "添加")
    public Boolean collection(Long readId) {
        return readService.loveCollection(readId, SharingType.COLLECTION.getCode());
    }

}
